import store from '@/store/index.js'
const db = uniCloud.database();
const dbCmd = db.command

class GetOrderObj {
	//获取当前用户订单  存到vuex

	//status 订单状态   is_handle 是否处理完成  根据不同参数 查询不同状态的订单
	async getOrderGoodsList(status) {
		let orders = []
		let orderGoodsList = []
		store.commit('setOrders', orders)
		store.commit('setOrderGoodsList', orderGoodsList)

		let res = await db.collection('uni-id-base-order').where({
			user_id: uniCloud.getCurrentUserInfo().uid,
			status: status,
		}).get()
		let goods_ids = []
		for (var i = 0; i < res.result.data.length; i++) {
			goods_ids[i] = res.result.data[i].goods_id
			orders[i] = res.result.data[i]
		}
		for (var i = 0; i < orders.length; i++) {
			res = await db.collection('opendb-mall-goods').where({
				_id: goods_ids[i]
			}).get()
			orderGoodsList[i] = res.result.data
		}
		store.commit('setOrders', orders)
		store.commit('setOrderGoodsList', orderGoodsList)
	}
}

export {
	GetOrderObj
}